<link href="${rc.getContextPath()}/manage/css/dwzCustomCss/dwz.custom.css?v=${ver}" rel="stylesheet" type="text/css">
<link rel='stylesheet' href='${rc.getContextPath()}/manage/styles/colorPicker/spectrum.css' />
<style>
.da span.error {
    position: absolute !important;
    left: 258px;
}

#itemTbody tr td div {
    height: 29px;
    padding-top: 3px;
}
</style>


<form method="post" action="${rc.getContextPath()}/manage/calendarPattern/saveCalendarPattern" class=" pageForm required-validate" onsubmit="return calendarPatternJs._tsubmit(this);">
    <div class="pageContent">
        <div class="pageFormContent">
            <fieldset>
                <input type="hidden" name="navTabId" value="${navTabId!''}"> <input type="hidden" name="id" value="<#if (calendarPattern.calendarPatternCode)??>${calendarPattern.calendarPatternCode!''}</#if>">
                <dl>

                    <dt><@label key="calendarPatternCode.C,colon">日历模式编号：</@label></dt>
                    <dd>
                        <input class="required  alphanumeric toUp" name="calendarPatternCode" value="<#if (calendarPattern.calendarPatternCode)??>${calendarPattern.calendarPatternCode!''}</#if>" type="text" maxlength="20"<#if (calendarPattern.calendarPatternCode)??> readonly="readonly"<#else> remote="${rc.getContextPath()}/manage/calendarPattern/validateCalendarPattern"</#if> warn="<@label key="calendarPatternCodeExist.M">日历模式编号已经存在</@label>"/>
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="calendarPatternText.C,colon">日历模式描述：</@label></dt>
                    <dd>
                        <input class="required" name="calendarPatternText" value="<#if (calendarPattern.calendarPatternText)??>${calendarPattern.calendarPatternText!''}</#if>" type="text" maxlength="60" />
                    </dd>
                </dl>

                <dl>
                    <dt><@label key="baseDate.C,colon">基准日期：</@label></dt>
                    <dd class='da'>
                        <input type="text" class="required date" readonly="readonly" name="baseDate" dateFmt="yyyy-MM-dd" value="<#if (calendarPattern.baseDate)??>${calendarPattern.baseDate?string("yyyy-MM-dd")}</#if>"/> <a class="inputDateButton" href="javascript:;"><@label key="select.B">选择</@label></a>
                    </dd>
                </dl>
                <dl>
                    <dd>
                        <label><input type="checkbox" name="lockFlag" value="1"<#if (calendarPattern.lockFlag)?? && (calendarPattern.lockFlag == 1)> checked="true"</#if>><@label key="lockFlag.C">锁定标记</@label></label>
                    </dd>
                </dl>
                <dl class="nowrap">
                    <dd>

                        <div class="panel" currentIndex="0" eventType="click" style="width: 605px; margin: 0;">
                            <h1><@label key="project.C">项目</@label></h1>
                            <div>
                                <div id="bar" class="pBar">
                                    <ul class="toolBar">
                                        <li><a class="add" href="javascript:void(0);" onclick="calendarPatternJs._addRow();"> <span><@label key="add.B">新增</@label></span> </a></li>
                                    </ul>
                                </div>
                                <table id="itemTable" class="table border canopration" width="610px"
                                    <#if (calendarPattern.calendarPatternCode)??>layoutH="230"<#else>layoutH="230"</#if>>
                                    <thead>
                                            <tr>        
                                                <th width="180" style="padding-left: 3px;"><@label key="serialNumber.C">序号</@label></th>
                                                <th width="190"><@label key="days.C">天数</@label></th>
                                                <th width="200"><@label key="dayType.C">日类型</@label></th>
                                                <th ><@label key="opera.C">操作</@label></th>
                                            </tr>
                                        </thead>
                                        <tbody id="itemTbody">
                                        <#if calendarPattern.items??&&(calendarPattern.items?size>0) >
                                         <#list calendarPattern.items as item>
                                        <tr style='height: 30px'>
                                            <td style="padding-left: 3px;"><input type='text' name='items[${item_index}].ordinal' class='digits textInput required' maxlength='2' value='${item.ordinal}'></td>
                                            <td><input type='text' name='items[${item_index}].days' class='digits textInput required' maxlength='2' value='${item.days}'></td>
                                            <td>
                                            <select name='items[${item_index}].dayTypeCode'>
                                             <option value=''></option>
                                             <#list types as type>
                                               <option value='${type.dayTypeCode}' <#if  (item.dayTypeCode)??&& type.dayTypeCode==item.dayTypeCode> selected='selected'</#if>>${type.dayTypeCode}-${type.dayTypeText}</option>
                                             </#list>
                                             <#if item.dayTypeLock==1>
                                             <option value='${item.dayTypeCode}' selected='selected'>${item.dayTypeCode}-${item.dayTypeText}</option>
                                             </#if>
                                            </select>
                                            </td>
                                            <td><a title="<@label key='delete.B'>删除</@label>" class='btnDel' href='javascript:void(0)' onclick='workDayTypeJs._deleteRow(this);'><@label key='delete.B'>删除</@label></a>
                                            </td>
                                        </tr>
                                        </#list>
                                         </#if>
                                        </tbody>
                                    </table>
                            </div>
                        </div>
                    </dd>
                </dl>
            </fieldset>
        </div>
        <#if (material.materialCode)??> <#assign createInfo=material/> <#include "/common/createInfo.html"> </#if>
        <div class="formBar">
            <ul>
                <li><div class="buttonActive" id="save">
                        <div class="buttonContent">
                            <button type="submit"><@label key="save.B">保存</@label></button>
                        </div>
                    </div></li>
                <li>
                    <div class="buttonActiveGrey">
                        <div class="buttonContent">
                            <button type="button" class="close"><@label key="cancel.B">取消</@label></button>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</form>



<script type="text/javascript">

    var calendarPatternJs = {
        _addRow : function() {
            var gridTheadTh = $("#itemTable", $.pdialog.getCurrent()).find(
                    "table thead th");
            var statrtNum = $("#itemTable tbody tr", $.pdialog.getCurrent()).length;
            var ops="<option value=''></option>";
             <#list types as type>
             ops+="<option value='${type.dayTypeCode}'>${type.dayTypeCode}-${type.dayTypeText}</option>";
            </#list>
            var row = "<tr style='height:30px'><td style='position: relative;padding-left: 3px;width:"
                    + $(gridTheadTh[0]).width()
                    + "px;' class='dataPick'><input type='text' name='items["+statrtNum+"].ordinal' class='digits textInput required' maxlength='2'></td>"
                    + "<td style='position: relative; width:"
                    + $(gridTheadTh[1]).width()
                    + "px;' class='dataPick'><input type='text' name='items["+statrtNum+"].days' min='1' class='digits textInput required' maxlength='2'></td>"
                    + "<td style='width:"
                    + $(gridTheadTh[2]).width()
                    + "px;'><select name='items["+statrtNum+"].dayTypeCode'>"
                    + ops+"</select></td>"
                    + "<td style='width:"
                    + $(gridTheadTh[3]).width()
                    + "px;'>"
                    + "<a title='"
                    + "<@label key='delete.B'>删除</@label>'"
                    + " class='btnDel' href='javascript:void(0)' onclick='calendarPatternJs._deleteRow(this);'><@label key='delete.B'>删除</@label></a></td></tr>";
            var tobdy = $("#itemTbody", $.pdialog.getCurrent());
            tobdy.append(row);
        },
        _deleteRow : function(a) {
            $(a).parents("tr").remove();
        },
        _tsubmit : function(t) {
            var $form = $(t);
            if (!$form.valid()) {
                return false;
            }
            var tableData=new Array();
            var isOk=true;
             $("#itemTbody tr", $.pdialog.getCurrent()).each(function(trindex,tritem){
                    tableData[trindex]=new Array();
                    $(tritem).find("td").each(function(tdindex,tditem){
                        var text;
                        if(tdindex<2)
                        {
                        text=$(tditem).find("input").val();
                        tableData[trindex][tdindex]=text;
                        }
                        else if(tdindex==2)
                        {
                            text=$(tditem).find("select").val();
                            tableData[trindex][tdindex]=text;
                        }
                    });
             });
             
             var allempt=true;
             var ary = new Array();
             for(var i=0;i<tableData.length;i++){
             if(tableData[i][2]!="")
                 {
                 allempt=false;
                 }
             ary[i]=tableData[i][0];
             }
              if( /(\x0f[^\x0f]+)\x0f[\s\S]*\1/.test("\x0f"+ary.join("\x0f\x0f") +"\x0f"))
                 {
                 alertMsg.warn("<@label key='ordinaRepeat.M'>序号不可重复！</@label>");
                 return false; 
                 }
              if(allempt)
              {
                  alertMsg.warn("<@label key='dayTypeAllNull.M'>日类型不可全部为空！</@label>");
                  return false; 
              }
             return validateCallback(t, dialogAjaxDone);
        }
    }
</script>
